package com.example.springboot.mapper;
import org.apache.ibatis.annotations.*;
import java.util.List;
import com.example.springboot.pojo.Comment;

@Mapper
public interface CommentMapper {
    @Select({
            "SELECT c.id,c.content,c.create_time,u.nick_name AS nickname,u.user_photo AS userPhoto,u.username AS username",
            "FROM comment c ",
            "LEFT JOIN user u ON c.user_id = u.id "})
    List<Comment> findAll();
    @Select({
            "SELECT c.id,c.content,c.create_time,u.username AS username",
            "FROM comment c ",
            "LEFT JOIN user u ON c.user_id = u.id " ,
            "WHERE u.username=#{username}"})
    List<Comment> findByUserName(String username);

    @Select({
            "SELECT c.id,c.content,c.create_time,u.nick_name AS nickname,u.user_photo AS userPhoto",
            "FROM comment c ",
            "LEFT JOIN user u ON c.user_id = u.id " ,
            "WHERE c.user_id=#{userId}"})
    List<Comment> findByUserId(Integer userId);
    @Insert("insert into comment(user_id,content,create_time) " +
            "values(#{userId},#{content},now())")
    void create(Comment comment);
    @Delete("delete from comment where id=#{id}")
    void delete(Integer id);


}
